<?php
// include function files for this application
require_once('/home/domains/uny-con.com/public_html/uny-con_fns.php');
if (!session_id()) { session_start(); }


//This is an admin only script so first lets check to make sure the user is valid and an admin. then we can do toher stuff.

if (!check_valid_user() || ($_SESSION['admin'] != 't')) {
	do_html_header('Unauthorized access', staysmall, $uny);
	echo 'You are not logged in or are not authorized to view this page. Please move along.';
	print_brs(6);
	do_html_footer(news);
	exit;
	}

	do_html_header('Payment received by type', staysmall, $uny);

if (!($conn = db_connect())) return false;

$pgtrans_log = pg_query("SELECT type, count(type) AS number_of_type, sum(amount) AS rev_from_sources
    FROM trans_log
   GROUP BY type
ORDER by rev_from_sources DESC");

echo "<h1>Payments received</h1>\n";

//trying to do an output table:
	echo "<table>\n";
	echo "	<tr class=\"grey_back\">\n";
	echo "		<th class=\"eventlist\"><strong>Transaction Type</strong></th>\n";
	echo "		<th class=\"eventlist\"><strong>Num Of Transactions</strong></th>\n";
	echo "		<th class=\"eventlist\"><strong>Revenue from Transaction</strong></th>\n";
	echo "	</tr>\n";
	$i = 0;
		
while ($row = pg_fetch_array($pgtrans_log)) {
		extract($row);
//print each row
		echo "	<tr$greyback>\n";
		echo "		<td class=\"eventlist\">$type</td>\n";
		echo "		<td class=\"eventlist\">$number_of_type</td>\n";
		echo "		<td class=\"eventlist\">$rev_from_sources</td>\n";
		
		echo "	</tr>\n";
		if (oddeven($i) == 'even') $greyback = " class=\"grey_back\"";
		if (oddeven($i) == 'odd') $greyback = "";
		$i++;
	}

$pgtotal = pg_query("SELECT count(*) AS total, sum(amount) AS rev
FROM trans_log");
$totals = pg_fetch_array($pgtotal);
$total = $totals['total'];
$rev = $totals['rev'];
echo "	<tr$greyback>\n";
echo "		<td class=\"eventlist\"><strong>Total</strong></td>\n";
echo "		<td class=\"eventlist\"><strong>$total</strong></td>\n";
echo "		<td class=\"eventlist\"><strong>$rev</strong></td>\n";
echo "	</tr>\n";
echo "</table>";




do_html_footer(news);